package com.yumao.recyclerview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<String> list;
    private MyAdapter2 adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        initData();
        adapter = new MyAdapter2(this, list);
        adapter.setListener(new MyAdapter2.RecyclerClickListener() {
            @Override
            public void onClick(int position, int layoutPosition) {
                T.showToast("click" + layoutPosition);
            }

            @Override
            public void onLongClick(int position, int layoutPosition) {
                adapter.delete(position, layoutPosition);
            }
        });
        recyclerView.setAdapter(adapter);
        //设置RecylerView 布局管理
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
    }

    private void initData() {
        list = new ArrayList<>();
        for (int i = 'a'; i < 'z'; i++) {
            list.add("" + (char) i);
        }
    }
}
